#include <stdio.h>
#include "aimage.h"
#include "accumulate.h"
#include "aimage_utils.h"
#include "aimage_dcraw.h"
#include "aimage_ppm.h"
#include <assert.h>
#include <stdlib.h>

int main( int argc, char *argv[] )
{
	bool first=true;
	int i;
	AIMAGE frame;
	AIMAGE hotmap;
	ACCUMULATOR darkframe;

	ASTAR_TRANSFORM t;

	AIMAGE_PPM_UTILS::load( hotmap, "hotmap.ppm");

	for ( i = 1; i < argc; ++i )
	{
		//t.xo = (rand() % 64) - 32;
		//t.yo = (rand() % 64) - 32;
		t.xo = 0.0f;
		t.yo = 0.0f;
		t.angle = 0.0f;

		fprintf(stderr,"dark reading %s\n", argv[i] );
		AIMAGE_DCRAW_UTILS::load( frame, argv[ i ] );
		
		if ( first )
		{
			int width, height;
			frame.get_dim( width, height );
			darkframe.alloc_image( width, height );
			first = false;
		}

		AIU::correct_for_hotmap( frame, hotmap );
		darkframe.rotate_and_add( frame, t );
	}
	assert( !first );

	darkframe.to_image( frame );
	AIMAGE_PPM_UTILS::save( frame, "dark.ppm", true );
}

